package api

import (
	"360-cinema/user-server/basic/inits"
	"360-cinema/user-server/basic/pkg"
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
	"strconv"
	"time"
)

func SendSms(c *gin.Context) {

	tel := c.Query("tel")
	code := rand.Intn(900000) + 100000
	_, err := pkg.SendSms(tel, strconv.Itoa(code))
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 0,
			"msg":  "短信发送失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "短信发送成功",
	})
	inits.Rdb.Set(inits.Ctx, "sendSms", code, time.Hour*5)

}
